﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Web;

using System.Configuration;
using PhotoGallery.Core.Business;

namespace PhotoGallery.Application
{
    public static class UserSession
    {
        private static readonly string accountFieldName = "user";

        private static readonly string permisssionsName = "permission";

        static UserSession()
        {
            // TODO: Remove this Initialization.
        }

        /// <summary>
        /// 是否用户在线
        /// </summary>
        public static Boolean IsOnline
        {
            get { return OnlineAccount != null; }
        }

        /// <summary>
        /// 获取或者设置当前在线用户
        /// </summary>
        public static Account OnlineAccount
        {
            get
            {
                if (HttpContext.Current.Session != null)
                {
                    Account account = HttpContext.Current.Session[accountFieldName] as Account;
                    return account;
                }
                else
                    return null;
            }
            set
            {
                HttpContext.Current.Session[accountFieldName] = value;
            }
        }

        public static HashSet<Operation> OnlineAccountPermission
        {
            get
            {
                return HttpContext.Current.Session[permisssionsName] as HashSet<Operation>;
            }
            set
            {
                HttpContext.Current.Session[permisssionsName] = value;
            }
        }

        public static void Clean()
        {
            HttpContext.Current.Session.Clear();
        }
    }
}
